<template>
    <view>
        <!-- pages/user/recommend/index.wxml -->
        <!-- 头部 -->
        <navber id="head-navber" :navbarData="navbarData"></navber>

        <!-- 商品 -->
        <hot :hotData="hotData" :isEdit="isEdit" :address="loca_address" @events="edit_submit"></hot>

        <view class="not-data" v-if="hotData.length == 0">
            <image :src="imgUrl + '/imgs/user/recommend/not_data.png'"></image>
        </view>
    </view>
</template>

<script>
import navber from '@/components/navber/index';
import hot from '@/components/hot/index';
// pages/user/recommend/index.js
const app = getApp();

const Api = require('../../../api/index.js');

const Config = require('../../../config/index.js');

export default {
    components: {
        navber,
        hot
    },
    data() {
        return {
            navbarData: {
                title: '推荐商品' //顶部标题
            },

            //导航栏
            imgUrl: Config.imgUrl,

            //图片url
            loca_address: {
                nation: '',
                //国
                province: '',
                //省
                city: '',
                //市
                district: '',
                //区
                street: '',
                //街道
                street_number: '' //门牌
            },

            //定位地址
            hotData: [],

            isEdit: false,
            pagenow: 1,
            dataList: []
        };
    },
    onReachBottom: function (e) {
        //滚动底部
        var page = this.pagenow + 1;
        this.setData({
            pagenow: page
        });
        this.getData();
    },
    onShow() {
        this.setData({
            dataList: [],
            loca_address: app.globalData.addressInfo
        });
        this.getData();
    },
    onPullDownRefresh(e) {
        this.getData();
        uni.stopPullDownRefresh();
    },
    methods: {
        edit_submit(e, _dataset) {
            
            if (!e.currentTarget) {
                if (_dataSet.tagId) {
                    e.currentTarget = {
                        id: _dataSet.tagId
                    };
                } else {
                    e.currentTarget = {
                        dataset: _dataSet
                    };
                }
            }
            
            //编辑提交
            console.log(e);
        },

        getData() {
            //获取数据
            var json = {
                type: 2,
                //推荐
                pagenow: this.pagenow
            };
            Api.userCollectOrUp(json).then((res) => {
                if (res.data.length > 0) {
                    var data = this.dataList;
                    data = data.concat(res.data);
                    this.setData({
                        hotData: data
                    });
                } else {
                    uni.showToast({
                        title: '暂无数据',
                        icon: 'none',
                        duration: 2000
                    });
                }
            });
        }
    }
};
</script>
<style>
@import './index.css';
</style>
